//
//  FamilyService.m
//  AILock
//
//  Created by 谭亚明 on 2020/6/23.
//  Copyright © 2020 tym. All rights reserved.
//

#import "FamilyService.h"
#import "YYModel.h"
#import "UserModel.h"
#import "LMJBaseResponse.h"
@implementation FamilyService

/*设置业务密码*/
-(void)getUpdateoperationpwd:(NSString*)pwdStr completion:(void(^)(LMJBaseResponse  *responObjec))completion{
    
    NSDictionary *dic = @{@"operationPassword":pwdStr};
    [self POST:urlOperationpwd parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
}


/*是否记住业务密码*/
-(void)getRememberoppwd:(BOOL)rememberOpPwd completion:(void(^)(LMJBaseResponse  *responObjec))completion{
    
    NSDictionary *dic = @{@"rememberOpPwd":@(rememberOpPwd)};
    [self POST:urlRememberoppwd parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
}

/*用户申请加入家庭*/
-(void)getFamilyuserapplyFamilyId:(NSInteger)famileId completion:(void(^)(LMJBaseResponse*   responObjec))completion{
    
    NSDictionary *dic = @{@"familyId":@(famileId)};
   [self POST:urlFamilyuserapply parameters:dic completion:^(LMJBaseResponse *response) {
       completion(response);
   }];
}

/*用户取消申请*/
-(void)getFamilyuserCancelapplyApplyId:(NSInteger)applyId completion:(void(^)(NSError *error,id  responObjec))completion{
    
   NSDictionary *dic = @{@"id":@(applyId)};
   [self POST:urlFamilyusercancelapply parameters:dic completion:^(LMJBaseResponse *response) {
       completion(response.error,response);
   }];
}

/*家长审核申请*/
-(void)getFamilyuserAuditapplyId:(NSInteger)applyId status:(NSInteger)staus auditDesc:(NSString*)desc completion:(void(^)(NSError *error,id  responObjec))completion{
    
    NSDictionary *dic = @{@"id":@(applyId),
                          @"status":@(staus),
                          @"auditDesc":desc
    };
    [self POST:urlFamilyuserauditapply parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response.error,response);
    }];
}

/*获取用户自己的申请信息*/
-(void)getFinduserApplyscompletion:(void(^)(NSError *error,NSArray<ApplyforModel*>  *array))completion{
    
    [self GET:urlFamilyuserfinduserapplys parameters:nil completion:^(LMJBaseResponse *response) {
        completion(response.error,[NSMutableArray yy_modelArrayWithClass:[ApplyforModel class] json:response.responseObject[@"data"]]);
    }];
}

/*获得家庭成员信息列表*/
-(void)getFamilyuserfindfamilyusers:(NSInteger)familyId status:(NSInteger)status type:(NSInteger)type completion:(void(^)(NSError *error, NSArray<UserModel*>  *array))completion{
    
    
    NSDictionary *dic = @{@"familyId":@(familyId),
                          @"status":@(status),
                          @"type":@(type)};
    [self GET:urlFamilyuserfindfamilyusers parameters:dic completion:^(LMJBaseResponse *response) {
       completion(response.error,[NSArray yy_modelArrayWithClass:[UserModel class] json:response.responseObject[@"data"]]);
    }];
}

/*获取用户当前默认家庭*/
-(void)getFamilyUserCurrentCompletion:(void(^)(LMJBaseResponse *sponse, FamilyModel *response))completion{
    
    [self GET:urlCurrentfamily parameters:nil completion:^(LMJBaseResponse *response) {
        completion(response,[FamilyModel yy_modelWithJSON: response.responseObject[@"data"]]);
    }];
}

/*创建家庭*/
-(void)getCreatFamilyWithFamilyName:(NSString*)name desc:(NSString*)familyDesc image:(NSString*)image completion:(void(^)(NSError *error, LMJBaseResponse *response))completion{
    
    NSDictionary *dic = @{@"familyName":name,
                          @"familyDesc":familyDesc?familyDesc:@"",@"image":image?image:@""};
    [self POST:urlCreatefamily parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response.error,response);
    }];
    
}

/*修改家庭信息*/
-(void)getUpdateFamilyWithFamilyId:(NSInteger)famileId FamilyName:(NSString*)name desc:(NSString*)familyDesc image:(NSString*)image completion:(void(^)(LMJBaseResponse *response))completion{
    
    NSDictionary *dic = @{@"familyId":@(famileId),
                          @"familyName":name,@"familyDesc":familyDesc?familyDesc:@"",
                          @"image":image
    };
    [self POST:urlUpdatefamily parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
    
}

/*获取家庭所有设备*/
-(void)getFamilyAllEquipmentWithFamilyId:(NSInteger)famileId completion:(void(^)(NSError *error,NSArray<EquipmentModel*>  *array))completion{
    
    NSDictionary *dic = @{@"familyId":@(famileId)};
    [self POST:urlFindfamilyequipmenty parameters:dic completion:^(LMJBaseResponse *response) {
       completion(response.error,[NSMutableArray yy_modelArrayWithClass:[EquipmentModel class] json:response.responseObject[@"data"]]);
    }];
}

/*删除家庭用户/移除黑名单*/
-(void)getFamilyuserdeletefamilyusers:(NSInteger)famileId completion:(void(^)(LMJBaseResponse  *respons))completion{
    
    NSDictionary *dic = @{@"familyUserId":@(famileId)};
    [self POST:urlFamilyuserdeletefamilyusers parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
    
}

/*授予用户家长*/
-(void)getFamilyusergrantpatriarch:(NSInteger)famileuseId completion:(void(^)(NSError *error,id  respons))completion{
    
    NSDictionary *dic = @{@"familyUserId":@(famileuseId)};
    [self POST:urlFamilyusergrantpatriarch parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response.error,response);
    }];
}

/*获得家庭的用户申请信息*/
-(void)getFamilyFpplysWithFamilyId:(NSInteger)famileId completion:(void(^)(NSError *error,NSArray<ApplyforModel*>  *array))completion{
    
    NSDictionary *dic = @{@"familyId":@(famileId)};
    [self GET:urlFamilyuserfindapply parameters:dic completion:^(LMJBaseResponse *response) {
       completion(response.error,[NSMutableArray yy_modelArrayWithClass:[ApplyforModel class] json:response.responseObject[@"data"]]);
    }];
}

/*查找家庭*/
-(void)getFindFamilysWithName:(NSString*)name page:(NSInteger)page size:(NSInteger)size completion:(void(^)(NSError *error,NSArray<FamilyModel*>  *array))completion{
    
    NSDictionary *dic = @{@"name":name,@"size":@(size)};
    [self GET:urlFamilyFindfamilys parameters:dic completion:^(LMJBaseResponse *response) {
        
        
        completion(response.error,[NSArray yy_modelArrayWithClass:[FamilyModel class] json:response.responseObject[@"data"][@"content"]]);
    }];
    
}

/*获取用户家庭列表*/
-(void)getFindFamilysCompletion:(void(^)(NSError *error, NSArray<FamilyModel*> *array))completion{
    
    [self GET:urlFindfamilys parameters:nil completion:^(LMJBaseResponse *response) {
        completion(response.error,[NSArray yy_modelArrayWithClass:[FamilyModel class] json:response.responseObject[@"data"]]);
    }];
}

/*获取用户家庭信息*/
-(void)getFindFamilyWithFamilyID:(NSInteger)familyID Completion:(void(^)(NSError *error, FamilyModel *model))completion{
    
    NSDictionary *dic = @{@"familyId":@(familyID)};
    [self GET:urlInfofindfamily parameters:dic completion:^(LMJBaseResponse *response) {
        
        completion(response.error,[FamilyModel yy_modelWithJSON:response.responseObject[@"data"]]);
    }];
}

/*根据familyId获取家庭详情*/
-(void)getFindfamilyDetailWithFamilyID:(NSInteger)familyID Completion:(void(^)(NSError *error, FamilyModel *model))completion{
    
    NSDictionary *dic = @{@"familyId":@(familyID)};
    [self GET:urlInfofindfamily parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response.error,[FamilyModel yy_modelWithJSON:response.responseObject[@"data"]]);
    }];
}

/*切换/进入家庭*/
-(void)getSwitchoverFamilyWithFamilyID:(NSInteger)familyID Completion:(void(^)(LMJBaseResponse * responsed))completion{
    
    NSDictionary *dic = @{@"familyId":@(familyID)};
    [self POST:urlSwitchoverfamily parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
}

/*退出家庭*/
-(void)getExitfamilyWithFamilyID:(NSInteger)familyID Completion:(void(^)(LMJBaseResponse *responsed))completion{
    
    NSDictionary *dic = @{@"familyId":@(familyID)};
    [self POST:urlExitfamily parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
}


/*添加游客用户*/
-(void)getAddequipmentgroupuser:(NSInteger)familyId
                     nickname:(NSString*)nickName
                     heakImaUrl:(NSString*)headImage
                    equipmentID:(NSInteger)equipmentid
                     Completion:(void(^)(LMJBaseResponse *responsed))completion{
    
    NSDictionary *dic = @{@"familyId":@(familyId),
                          @"nickname":nickName,
                          @"headImgUrl":headImage?headImage:@"",
                          @"equipmentId":@(equipmentid)
    };
    [self POST:urlFamilyuseraddequipmentgroupuser  parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
}

/*删除游客用户*/
-(void)getDeleteequipmentgroupuser:(NSInteger)famileId
                        userID:(NSInteger)userID
                        deleteEquipmentUser:(BOOL)equDele
                        completion:(void(^)(LMJBaseResponse  *respons))completion{
    
    
    NSDictionary *dic = @{@"familyId":@(famileId),
                          @"id":@(userID),
                          @"deleteEquipmentUser":@(equDele),
    };
    [self POST:urlDeleteequipmentgroupuser  parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];

}

/*游客绑定用户*/
-(void)getGroupuserbindappuserFamily:(NSInteger)familyID groupUserId:(NSInteger)groupUserId
userId:(NSInteger)userId
                         equipmentId:(NSInteger)equipmentId
                          Completion:(void(^)(LMJBaseResponse * responsed))completion{
    
    NSDictionary *dic = @{@"familyId":@(familyID),
                          @"groupUserId":@(groupUserId),
                          @"userId":@(userId),
                          @"equipmentId":@(equipmentId)
    };
    [self POST:urlFamilyusergroupuserbindappuser  parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
    
}

/*修改家庭用户状态*/
-(void)getUpdatefamilyuserstatus:(NSInteger)familyUserId
                          status:(NSInteger)status Completion:(void(^)(LMJBaseResponse *responsed))completion{
    
    NSDictionary *dic = @{@"familyUserId":@(familyUserId),
                          @"status":@(status)
    };
    [self POST:urlFamilyuserupdatefamilyuserstatus  parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
    
}
@end
